

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="风间">
  <meta name="keywords" content="">
  
    <meta name="description" content="1. 如果不用会怎么样目前搜索的弊端（直接查数据库）：  空格支持 x 拆词查询 × 搜索内容高亮 ×  海量数据查询 ×  2. 什么是分布式搜索引擎2.1 概念 首先是搜索引擎 其次支持分布式存储与搜索  2.2 Lucene vs Solr  vs ElasticSearch Lucene 是类库：  基于 java 的全文搜索引擎，它不是一个应用程序，它是一个代码库或者是一些 api 供我">
<meta property="og:type" content="article">
<meta property="og:title" content="分布式搜索引擎-ElasticSearch">
<meta property="og:url" content="http://example.com/2023/05/08/%E5%90%8E%E7%AB%AF/java/ElasticSearch/index.html">
<meta property="og:site_name" content="风间小栈">
<meta property="og:description" content="1. 如果不用会怎么样目前搜索的弊端（直接查数据库）：  空格支持 x 拆词查询 × 搜索内容高亮 ×  海量数据查询 ×  2. 什么是分布式搜索引擎2.1 概念 首先是搜索引擎 其次支持分布式存储与搜索  2.2 Lucene vs Solr  vs ElasticSearch Lucene 是类库：  基于 java 的全文搜索引擎，它不是一个应用程序，它是一个代码库或者是一些 api 供我">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/fengjian2705/cdn/img/proxy/proxy01.jpg">
<meta property="article:published_time" content="2023-05-08T01:46:03.859Z">
<meta property="article:modified_time" content="2023-05-08T13:20:10.207Z">
<meta property="article:author" content="风间">
<meta property="article:tag" content="搜索引擎">
<meta property="article:tag" content="ElasticSearch">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/fengjian2705/cdn/img/proxy/proxy01.jpg">
  
  
  <title>分布式搜索引擎-ElasticSearch - 风间小栈</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.13","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":"§"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>风间小栈</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/%E6%96%87%E6%9C%AC.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="分布式搜索引擎-ElasticSearch">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2023-05-08 09:46" pubdate>
        2023年5月8日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      9.6k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      81 分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">分布式搜索引擎-ElasticSearch</h1>
            
            <div class="markdown-body">
              <h2 id="1-如果不用会怎么样"><a href="#1-如果不用会怎么样" class="headerlink" title="1. 如果不用会怎么样"></a>1. 如果不用会怎么样</h2><p>目前搜索的弊端（直接查数据库）：</p>
<ul>
<li>空格支持 <font color="red">x</font></li>
<li>拆词查询 <font color="red">×</font></li>
<li>搜索内容高亮 <font color="red">× </font></li>
<li>海量数据查询 <font color="red">×</font></li>
</ul>
<h2 id="2-什么是分布式搜索引擎"><a href="#2-什么是分布式搜索引擎" class="headerlink" title="2. 什么是分布式搜索引擎"></a>2. 什么是分布式搜索引擎</h2><h3 id="2-1-概念"><a href="#2-1-概念" class="headerlink" title="2.1 概念"></a>2.1 概念</h3><ol>
<li>首先是搜索引擎</li>
<li>其次支持分布式存储与搜索</li>
</ol>
<h3 id="2-2-Lucene-vs-Solr-vs-ElasticSearch"><a href="#2-2-Lucene-vs-Solr-vs-ElasticSearch" class="headerlink" title="2.2 Lucene vs Solr  vs ElasticSearch"></a>2.2 Lucene vs Solr  vs ElasticSearch</h3><ol>
<li><p>Lucene 是类库：</p>
<ul>
<li>基于 java 的全文搜索引擎，它不是一个应用程序，它是一个代码库或者是一些 api 供我们调用的，本质上就是一个 jar 包，可以直接被引用（导入）到项目中去，然后调用它的 api 进行搜索集成</li>
<li>只能使用 java 进行整合，水平扩展集群的话比较复杂</li>
</ul>
</li>
<li><p>Solr 是基于 Lucene 构建的开源搜索引擎：</p>
<ul>
<li>本质上是对 Lucene 进行了一层封装，是 Apache 的一个开源项目，使用 java 开发的，可以独立部署到 Tomcat 或 jetty 中</li>
<li>可以通过 zookeeper 实现集群部署</li>
<li>提供分布式索引、负载均衡、自动故障转移恢复，可靠性、可扩展性和容错性都挺好</li>
</ul>
</li>
<li><p>ElasticSearch 也是基于 Lucene：</p>
<ul>
<li><p>分布式搜索引擎</p>
</li>
<li><p>restful 风格接口，支持不同开发语言调用</p>
</li>
<li><p>近实时的搜索服务</p>
</li>
<li><p>支持 PB（1024 T） 级别的搜索</p>
</li>
<li><p>大数据的分析</p>
</li>
</ul>
</li>
</ol>
<h2 id="3-ES-核心术语"><a href="#3-ES-核心术语" class="headerlink" title="3. ES 核心术语"></a>3. ES 核心术语</h2><ol>
<li>索引 index：        表</li>
<li><del>类型 type：         表逻辑类型</del></li>
<li>文档 document：行</li>
<li>字段 fields：        列</li>
<li>映射 mapping      表结构定义</li>
<li>近实时 NRT         Near real time</li>
<li>节点 node           每一台服务器都是一个节点</li>
<li>shard replica       数据分片与备份</li>
</ol>
<p><code>提示：</code> type 已在 ES 7.x 后废弃！</p>
<h2 id="4-什么是倒排索引"><a href="#4-什么是倒排索引" class="headerlink" title="4. 什么是倒排索引"></a>4. 什么是倒排索引</h2><p>需求：在 30 份文档中找出其中包含“张三”的文档，通常来说我们会根据把文档排序，然后依次遍历来判断当前遍历到的文档中是否包含“张三”，这种查找方式就是根据“文档id” -&gt; “文档内容”的对应关系依次判断文档内容是否包含“张三“，如果存在一张”张三“-&gt;”文档”的映射关系，我们可以直接根据张三来获取到满足条件的文档，这就是两种不同的方式进行索引：</p>
<p>正序：根据文档来确定文档中的内容</p>
<p>倒排：文档中的内容到文档的映射，这种就叫做倒排索引</p>
<h2 id="5-安装-ElasticSearch"><a href="#5-安装-ElasticSearch" class="headerlink" title="5. 安装 ElasticSearch"></a>5. 安装 ElasticSearch</h2><ol>
<li><p>下载安装包，<a target="_blank" rel="noopener" href="https://www.elastic.co/cn/downloads/elasticsearch">传送门</a></p>
</li>
<li><p>上传安装包到 linux 服务器，目录 <code>/home/software</code></p>
</li>
<li><p>解压文件到目录<code>/usr/local</code>，tar -zxvf xxx.tar </p>
</li>
<li><p>es文件目录结构：</p>
<ul>
<li><strong>bin</strong>：可执行文件，例如启动 es 的脚本文件就在这里</li>
<li><strong>config</strong>：配置问价存放位置<ul>
<li>elasticsearch.yml：核心配置文件</li>
<li>jvm.options</li>
<li>log4j2.properties</li>
<li>role_mapping.yml</li>
<li>roles.yml</li>
<li>users</li>
<li>users_rolse</li>
</ul>
</li>
<li><strong>jdk</strong>：依赖的 java 环境</li>
<li><strong>lib</strong>：依赖的一些类库</li>
<li>LINCENSE.txt</li>
<li><strong>logs</strong>：日志文件</li>
<li><strong>modules</strong>：跟 es 有关的模块</li>
<li>NOTICE.txt</li>
<li><strong>plugins</strong>：插件存放位置，包括自定义的</li>
<li>README.textile</li>
</ul>
</li>
<li><p>在 es 文件目录中新建 data 目录，数据目录，后续的索引存放位置</p>
</li>
<li><p>修改核心配置文件 <strong>elasticsearch.yml</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs yam"># 集群名称<br>cluster.name: fengjian-elasticsearch<br><br># 节点名称<br>node.name: es-node1<br><br># 数据路径<br>path.data: /usr/local/elasticsearch-7.4.2/data<br><br># 日志路径<br>path.logs: /usr/local/elasticsearch-7.4.2/logs<br><br># 网络地址绑定<br>network.host: 0.0.0.0<br><br># http 端口号<br>http.port: 9200<br><br># 集群启动时初始化节点列表<br>cluster.initial_master_nodes:[&quot;es-node1&quot;]<br><br></code></pre></td></tr></table></figure></li>
<li><p>修改 <strong>jvm.options</strong> 配置项</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs yam"># Xms 初始化堆空间<br># Xmx 最大堆空间<br>-Xms128m<br>-Xmx128m<br></code></pre></td></tr></table></figure></li>
<li><p>启动 ElasticSearch</p>
<ul>
<li><p><code>提示：</code>：root 用户是无法启动 es 的，需要创建一个新用户！    </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs she"># 添加用户<br>useradd esuser<br><br># 授权 1<br>chown -R esuser /usr/local/elasticsearch-7.4.2<br><br># 切换用户<br>su esuser<br><br># 授权 2，elasticsearch.keystore accessDenied!<br>chown -R esuser:esuser /usr/local/elasticsearch-7.4.2<br><br><br></code></pre></td></tr></table></figure></li>
<li><p>启动，./elasticsearch 或 ./elasticsearch（后台启动）</p>
<ul>
<li>异常 1：max file descriptors [4096]  -&gt; [65535]</li>
<li>异常 2：max number of threads [3756]  -&gt; [4096]</li>
<li>异常 3：max virtual memory areas vm.max_map_count [65530]  -&gt; [262144]</li>
</ul>
</li>
<li><p>修改配置 vim /etc/security/limits.conf，文件最后新增如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell">* soft nofile 65536<br>* hard nofile 131072<br>* soft nproc 2048<br>* hard nproc 4096<br></code></pre></td></tr></table></figure></li>
<li><p>修改配置文件 vim /etc/sysctl.conf，文件最后新增如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs she">vm.max_map_count=262145<br></code></pre></td></tr></table></figure>

<p>编译文件：sysctl -p</p>
</li>
<li><p>启动成功，浏览器中访问 192.168.12.23:9200 查看信息</p>
</li>
<li><p>关闭的话，jps elasticsearch 查看进程 id 后 kill id</p>
</li>
</ul>
<p><strong>提示</strong>：如果在网页上显示localhost未发送任何数据，修改配置文件如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs yam">xpack.security.enable: false<br><br>xpack.security.http.ssl:<br>	enabled: false<br></code></pre></td></tr></table></figure></li>
</ol>
<h2 id="6-安装-elasticsearch-head-插件"><a href="#6-安装-elasticsearch-head-插件" class="headerlink" title="6. 安装 elasticsearch-head 插件"></a>6. 安装 elasticsearch-head 插件</h2><h3 id="6-1-chrome-中谷歌市场中搜索-elasticsearch-进行安装即可"><a href="#6-1-chrome-中谷歌市场中搜索-elasticsearch-进行安装即可" class="headerlink" title="6.1 chrome 中谷歌市场中搜索 elasticsearch 进行安装即可"></a>6.1 chrome 中谷歌市场中搜索 elasticsearch 进行安装即可</h3><p>   <img src="https://s3.bmp.ovh/imgs/2023/02/13/55aface0b2e180da.png" srcset="/img/loading.gif" lazyload></p>
<h3 id="6-2-head-与-postman-基本操作"><a href="#6-2-head-与-postman-基本操作" class="headerlink" title="6.2  head 与 postman 基本操作"></a>6.2  head 与 postman 基本操作</h3><ol>
<li><p>版本信息查询</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/15/aeaf0be9dec3cb47.png" srcset="/img/loading.gif" lazyload alt="image-20230215103432717"></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs json">   GET http:<span class="hljs-comment">//192.168.X.X:9200/</span><br><br><span class="hljs-number">2.</span> 集群健康查询<br><br>   ![image<span class="hljs-number">-20230215101655801</span>](https:<span class="hljs-comment">//s3.bmp.ovh/imgs/2023/02/15/d0972558c7fcc4b8.png)</span><br><br>   ```json<br>   GET http:<span class="hljs-comment">//192.168.X.X:9200/_cluster/health</span><br></code></pre></td></tr></table></figure></li>
<li><p>新建索引：5 个分片，0 个副本</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/15/8d31a4573d3d9e8b.png" srcset="/img/loading.gif" lazyload alt="image-20230215131749500"></p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/15/d611cd6d6a89bd5f.png" srcset="/img/loading.gif" lazyload></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs json">PUT http:<span class="hljs-comment">//192.168.x.x:9200/index_demo</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;settings&quot;</span>:&#123;<br>        <span class="hljs-attr">&quot;number_of_shards&quot;</span>:<span class="hljs-number">5</span>,<br>        <span class="hljs-attr">&quot;number_of_replicas&quot;</span>:<span class="hljs-number">0</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>新建索引：5 个分片，1 个副本，未分配分片有 5 个</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/15/d22f2d842d3e9f41.png" srcset="/img/loading.gif" lazyload alt="image-20230215135509191"></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs json">PUT http:<span class="hljs-comment">//192.168.x.x:9200/index_123</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;settings&quot;</span>:&#123;<br>        <span class="hljs-attr">&quot;number_of_shards&quot;</span>:<span class="hljs-number">5</span>,<br>        <span class="hljs-attr">&quot;number_of_replicas&quot;</span>:<span class="hljs-number">1</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>删除索引：</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/15/3fe5fe90dce805d4.png" srcset="/img/loading.gif" lazyload alt="image-20230215141019148"></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs json">DELETE http:<span class="hljs-comment">//192.168.x.x:9200/index_123</span><br></code></pre></td></tr></table></figure></li>
<li><p>查询索引</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs json">GET http:<span class="hljs-comment">//192.168.x.x:9200/index_temp</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;index_temp&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;aliases&quot;</span>: &#123;&#125;,<br>        <span class="hljs-attr">&quot;mappings&quot;</span>: &#123;&#125;,<br>        <span class="hljs-attr">&quot;settings&quot;</span>: &#123;<br>            <span class="hljs-attr">&quot;index&quot;</span>: &#123;<br>                <span class="hljs-attr">&quot;routing&quot;</span>: &#123;<br>                    <span class="hljs-attr">&quot;allocation&quot;</span>: &#123;<br>                        <span class="hljs-attr">&quot;include&quot;</span>: &#123;<br>                            <span class="hljs-attr">&quot;_tier_preference&quot;</span>: <span class="hljs-string">&quot;data_content&quot;</span><br>                        &#125;<br>                    &#125;<br>                &#125;,<br>                <span class="hljs-attr">&quot;number_of_shards&quot;</span>: <span class="hljs-string">&quot;3&quot;</span>,<br>                <span class="hljs-attr">&quot;provided_name&quot;</span>: <span class="hljs-string">&quot;index_temp&quot;</span>,<br>                <span class="hljs-attr">&quot;creation_date&quot;</span>: <span class="hljs-string">&quot;1676441762678&quot;</span>,<br>                <span class="hljs-attr">&quot;number_of_replicas&quot;</span>: <span class="hljs-string">&quot;0&quot;</span>,<br>                <span class="hljs-attr">&quot;uuid&quot;</span>: <span class="hljs-string">&quot;ryzEGgNIS3ycfWfV-lhaOQ&quot;</span>,<br>                <span class="hljs-attr">&quot;version&quot;</span>: &#123;<br>                    <span class="hljs-attr">&quot;created&quot;</span>: <span class="hljs-string">&quot;7160099&quot;</span><br>                &#125;<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>查询全部索引概览</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs json">GET http:<span class="hljs-comment">//192.168.147.132:9200/_cat/indices?v</span><br><br>health status index            uuid                   pri rep docs.count docs.deleted store.size pri.store.size<br>green  open   .geoip_databases aqUccqm1RzCvrVBSqK6xfg   <span class="hljs-number">1</span>   <span class="hljs-number">0</span>         <span class="hljs-number">41</span>           <span class="hljs-number">36</span>     <span class="hljs-number">42.3</span>mb         <span class="hljs-number">42.3</span>mb<br>green  open   index_demo       h7rxnFLDTkOcGreaIBIiEw   <span class="hljs-number">5</span>   <span class="hljs-number">0</span>          <span class="hljs-number">0</span>            <span class="hljs-number">0</span>      <span class="hljs-number">1.1</span>kb          <span class="hljs-number">1.1</span>kb<br>green  open   index_temp       ryzEGgNIS3ycfWfV-lhaOQ   <span class="hljs-number">3</span>   <span class="hljs-number">0</span>          <span class="hljs-number">0</span>            <span class="hljs-number">0</span>       <span class="hljs-number">678</span>b           <span class="hljs-number">678</span>b<br><br></code></pre></td></tr></table></figure></li>
</ol>
<h2 id="7-mappings-索引数据结构定义"><a href="#7-mappings-索引数据结构定义" class="headerlink" title="7. mappings 索引数据结构定义"></a>7. mappings 索引数据结构定义</h2><h3 id="7-1-新建索引并设置-mapping"><a href="#7-1-新建索引并设置-mapping" class="headerlink" title="7.1 新建索引并设置 mapping"></a>7.1 新建索引并设置 mapping</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs json">PUT http:<span class="hljs-comment">//192.168.147.132:9200/index_mapping</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;mappings&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;properties&quot;</span>: &#123;<br>            <span class="hljs-attr">&quot;realname&quot;</span>: &#123;<br>                <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>,<br>                <span class="hljs-attr">&quot;index&quot;</span>: <span class="hljs-literal">true</span><br>            &#125;,<br>            <span class="hljs-attr">&quot;username&quot;</span>: &#123;<br>                <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;keyword&quot;</span>,<br>                <span class="hljs-attr">&quot;index&quot;</span>: <span class="hljs-literal">false</span><br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>realname：字段名    type：类型    index：是否被索引</p>
<table>
<thead>
<tr>
<th align="center">type</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">text</td>
<td align="center">字符串，可被分词</td>
</tr>
<tr>
<td align="center">keyword</td>
<td align="center">字符串，不可被分词</td>
</tr>
<tr>
<td align="center">long</td>
<td align="center">长整型</td>
</tr>
<tr>
<td align="center">integer</td>
<td align="center">整型</td>
</tr>
<tr>
<td align="center">float</td>
<td align="center">浮点型</td>
</tr>
<tr>
<td align="center">true</td>
<td align="center">布尔型</td>
</tr>
<tr>
<td align="center">byte</td>
<td align="center">字节</td>
</tr>
<tr>
<td align="center">boolean</td>
<td align="center">短整型</td>
</tr>
<tr>
<td align="center">date</td>
<td align="center">日期类型</td>
</tr>
<tr>
<td align="center">object</td>
<td align="center">对象类型</td>
</tr>
<tr>
<td align="center">double</td>
<td align="center">浮点数</td>
</tr>
<tr>
<td align="center">[1,2,3]</td>
<td align="center">数组类型</td>
</tr>
</tbody></table>
<p>index：是否被索引（查询）</p>
<p>keyword：无法被分词</p>
<h3 id="7-2-索引分词"><a href="#7-2-索引分词" class="headerlink" title="7.2 索引分词"></a>7.2 索引分词</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs json">GET http:<span class="hljs-comment">//192.168.147.132:9200/index_mapping/_analyze</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;field&quot;</span>: <span class="hljs-string">&quot;username&quot;</span>,<br>    <span class="hljs-attr">&quot;text&quot;</span>: <span class="hljs-string">&quot;good good study,day day up!&quot;</span><br>&#125;<br><br>&#123;<br>    <span class="hljs-attr">&quot;tokens&quot;</span>: [<br>        &#123;<br>            <span class="hljs-attr">&quot;token&quot;</span>: <span class="hljs-string">&quot;good good study,day day up!&quot;</span>,<br>            <span class="hljs-attr">&quot;start_offset&quot;</span>: <span class="hljs-number">0</span>,<br>            <span class="hljs-attr">&quot;end_offset&quot;</span>: <span class="hljs-number">27</span>,<br>            <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;word&quot;</span>,<br>            <span class="hljs-attr">&quot;position&quot;</span>: <span class="hljs-number">0</span><br>        &#125;<br>    ]<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="7-3-新增-mapping-中-properties"><a href="#7-3-新增-mapping-中-properties" class="headerlink" title="7.3 新增 mapping 中 properties"></a>7.3 新增 mapping 中 properties</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs json">POST http:<span class="hljs-comment">//192.168.147.132:9200/index_mapping/_mapping</span><br>&#123;<br>    <span class="hljs-attr">&quot;properties&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;id&quot;</span>: &#123;<br>            <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;long&quot;</span>,<br>            <span class="hljs-attr">&quot;index&quot;</span>: <span class="hljs-literal">true</span><br>        &#125;,<br>        <span class="hljs-attr">&quot;age&quot;</span>: &#123;<br>            <span class="hljs-attr">&quot;type&quot;</span>: <span class="hljs-string">&quot;integer&quot;</span>,<br>            <span class="hljs-attr">&quot;index&quot;</span>: <span class="hljs-literal">false</span><br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="8-文档的基本操作"><a href="#8-文档的基本操作" class="headerlink" title="8. 文档的基本操作"></a>8. 文档的基本操作</h2><h3 id="8-1-新建索引-my-doc，分片-1，副本-0"><a href="#8-1-新建索引-my-doc，分片-1，副本-0" class="headerlink" title="8.1 新建索引 my_doc，分片 1，副本 0"></a>8.1 新建索引 my_doc，分片 1，副本 0</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs sql">PUT http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.x.x:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<br><br>&#123;<br>    &quot;settings&quot;:&#123;<br>        &quot;number_of_shards&quot;:<span class="hljs-number">1</span>,<br>        &quot;number_of_replicas&quot;:<span class="hljs-number">0</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-2-新增文档信息"><a href="#8-2-新增文档信息" class="headerlink" title="8.2 新增文档信息"></a>8.2 新增文档信息</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><code class="hljs sql">POST http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span><span class="hljs-number">.147</span><span class="hljs-number">.132</span>:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">1</span><br><br>&#123;<br>    &quot;id&quot;:<span class="hljs-number">1001</span>,<br>    &quot;name&quot;:&quot;jack&quot;,<br>    &quot;age&quot;:<span class="hljs-number">18</span><br>&#125;<br><br><span class="hljs-operator">/</span><span class="hljs-operator">/</span> 新增成功<br>&#123;<br>    &quot;_index&quot;: &quot;my_doc&quot;,<br>    &quot;_type&quot;: &quot;_doc&quot;,<br>    &quot;_id&quot;: &quot;FCRSVYYB_DJayXIYu1rV&quot;,<br>    &quot;_version&quot;: <span class="hljs-number">1</span>,<br>    &quot;result&quot;: &quot;created&quot;,<br>    &quot;_shards&quot;: &#123;<br>        &quot;total&quot;: <span class="hljs-number">1</span>,<br>        &quot;successful&quot;: <span class="hljs-number">1</span>,<br>        &quot;failed&quot;: <span class="hljs-number">0</span><br>    &#125;,<br>    &quot;_seq_no&quot;: <span class="hljs-number">6</span>,<br>    &quot;_primary_term&quot;: <span class="hljs-number">1</span><br>&#125;<br><br><span class="hljs-operator">/</span><span class="hljs-operator">/</span> <span class="hljs-number">1</span> 是文档 id，可自定义，可系统生成，通过 es<span class="hljs-operator">-</span>head 查看文档<br><br>&quot;mappings&quot;: &#123;<br>    &quot;_doc&quot;: &#123;<br>        &quot;properties&quot;: &#123;<br>            &quot;name&quot;: &#123;<br>                &quot;type&quot;: &quot;text&quot;,<br>                &quot;fields&quot;: &#123;<br>                    &quot;keyword&quot;: &#123;<br>                        &quot;ignore_above&quot;: <span class="hljs-number">256</span>,<br>                        &quot;type&quot;: &quot;keyword&quot;<br>                    &#125;<br>                &#125;<br>            &#125;,<br>            &quot;id&quot;: &#123;<br>                &quot;type&quot;: &quot;long&quot;<br>            &#125;,<br>            &quot;age&quot;: &#123;<br>                &quot;type&quot;: &quot;long&quot;<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-3-删除文档"><a href="#8-3-删除文档" class="headerlink" title="8.3 删除文档"></a>8.3 删除文档</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DELETE</span> http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.X.X:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">2</span><br></code></pre></td></tr></table></figure>

<h3 id="8-4-修改文档-局部修改"><a href="#8-4-修改文档-局部修改" class="headerlink" title="8.4 修改文档-局部修改"></a>8.4 修改文档-局部修改</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs sql">UPDATE http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.X.X:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">1</span><span class="hljs-operator">/</span>_update<br><br>&#123;<br>    &quot;doc&quot;:&#123;<br>        &quot;name&quot;:&quot;春风得意马蹄疾啊&quot; <span class="hljs-operator">/</span><span class="hljs-operator">/</span> 指定修改内容<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-5-修改文档-全量修改"><a href="#8-5-修改文档-全量修改" class="headerlink" title="8.5 修改文档-全量修改"></a>8.5 修改文档-全量修改</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs sql">PUT http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.X.X:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">1</span><br><br>&#123;<br>    &quot;id&quot;: <span class="hljs-number">1005</span>,<br>    &quot;name&quot;: &quot;春风得意马蹄疾&quot;,<br>    &quot;age&quot;: <span class="hljs-number">20</span><br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-6-查询文档根据文档-id"><a href="#8-6-查询文档根据文档-id" class="headerlink" title="8.6 查询文档根据文档 id"></a>8.6 查询文档根据文档 id</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">GET</span> http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.x.x:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">1</span><br><br>&#123;<br>    &quot;_index&quot;: &quot;my_doc&quot;,<br>    &quot;_type&quot;: &quot;_doc&quot;,<br>    &quot;_id&quot;: &quot;1&quot;,<br>    &quot;_version&quot;: <span class="hljs-number">5</span>,<br>    &quot;_seq_no&quot;: <span class="hljs-number">11</span>,<br>    &quot;_primary_term&quot;: <span class="hljs-number">1</span>,<br>    &quot;found&quot;: <span class="hljs-literal">true</span>,<br>    &quot;_source&quot;: &#123;<br>        &quot;id&quot;: <span class="hljs-number">1005</span>,<br>        &quot;name&quot;: &quot;春风得意马蹄疾&quot;,<br>        &quot;age&quot;: <span class="hljs-number">20</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-7-查询全部"><a href="#8-7-查询全部" class="headerlink" title="8.7 查询全部"></a>8.7 查询全部</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">GET</span> http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.x.x:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span>_search<br><br>&#123;<br>    &quot;took&quot;: <span class="hljs-number">4</span>,<br>    &quot;timed_out&quot;: <span class="hljs-literal">false</span>,<br>    &quot;_shards&quot;: &#123;<br>        &quot;total&quot;: <span class="hljs-number">1</span>,<br>        &quot;successful&quot;: <span class="hljs-number">1</span>,<br>        &quot;skipped&quot;: <span class="hljs-number">0</span>,<br>        &quot;failed&quot;: <span class="hljs-number">0</span><br>    &#125;,<br>    &quot;hits&quot;: &#123;<br>        &quot;total&quot;: &#123;<br>            &quot;value&quot;: <span class="hljs-number">4</span>,<br>            &quot;relation&quot;: &quot;eq&quot;<br>        &#125;,<br>        &quot;max_score&quot;: <span class="hljs-number">1.0</span>,<br>        &quot;hits&quot;: [<br>            &#123;<br>                &quot;_index&quot;: &quot;my_doc&quot;,<br>                &quot;_type&quot;: &quot;_doc&quot;,<br>                &quot;_id&quot;: &quot;3&quot;,<br>                &quot;_score&quot;: <span class="hljs-number">1.0</span>,<br>                &quot;_source&quot;: &#123;<br>                    &quot;id&quot;: <span class="hljs-number">1003</span>,<br>                    &quot;name&quot;: &quot;风间&quot;,<br>                    &quot;age&quot;: <span class="hljs-number">19</span><br>                &#125;<br>            &#125;,<br>            &#123;<br>                &quot;_index&quot;: &quot;my_doc&quot;,<br>                &quot;_type&quot;: &quot;_doc&quot;,<br>                &quot;_id&quot;: &quot;FCRSVYYB_DJayXIYu1rV&quot;,<br>                &quot;_score&quot;: <span class="hljs-number">1.0</span>,<br>                &quot;_source&quot;: &#123;<br>                    &quot;id&quot;: <span class="hljs-number">1004</span>,<br>                    &quot;name&quot;: &quot;一日看尽长安花&quot;,<br>                    &quot;age&quot;: <span class="hljs-number">20</span><br>                &#125;<br>            &#125;,<br>            &#123;<br>                &quot;_index&quot;: &quot;my_doc&quot;,<br>                &quot;_type&quot;: &quot;_doc&quot;,<br>                &quot;_id&quot;: &quot;FSRWVYYB_DJayXIY8Voz&quot;,<br>                &quot;_score&quot;: <span class="hljs-number">1.0</span>,<br>                &quot;_source&quot;: &#123;<br>                    &quot;id&quot;: <span class="hljs-number">1005</span>,<br>                    &quot;name&quot;: &quot;春风得意马蹄疾啊&quot;,<br>                    &quot;age&quot;: <span class="hljs-number">20</span><br>                &#125;<br>            &#125;,<br>            &#123;<br>                &quot;_index&quot;: &quot;my_doc&quot;,<br>                &quot;_type&quot;: &quot;_doc&quot;,<br>                &quot;_id&quot;: &quot;1&quot;,<br>                &quot;_score&quot;: <span class="hljs-number">1.0</span>,<br>                &quot;_source&quot;: &#123;<br>                    &quot;id&quot;: <span class="hljs-number">1005</span>,<br>                    &quot;name&quot;: &quot;春风得意马蹄疾&quot;,<br>                    &quot;age&quot;: <span class="hljs-number">20</span><br>                &#125;<br>            &#125;<br>        ]<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-8-根据-id-查询，设置-source-查询字段，多个字段逗号隔开"><a href="#8-8-根据-id-查询，设置-source-查询字段，多个字段逗号隔开" class="headerlink" title="8.8 根据 id 查询，设置 source 查询字段，多个字段逗号隔开"></a>8.8 根据 id 查询，设置 source 查询字段，多个字段逗号隔开</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">GET</span> http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.x.x:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">1</span>?_source<span class="hljs-operator">=</span>name<br><br>&#123;<br>    &quot;_index&quot;: &quot;my_doc&quot;,<br>    &quot;_type&quot;: &quot;_doc&quot;,<br>    &quot;_id&quot;: &quot;1&quot;,<br>    &quot;_version&quot;: <span class="hljs-number">5</span>,<br>    &quot;_seq_no&quot;: <span class="hljs-number">11</span>,<br>    &quot;_primary_term&quot;: <span class="hljs-number">1</span>,<br>    &quot;found&quot;: <span class="hljs-literal">true</span>,<br>    &quot;_source&quot;: &#123;<br>        &quot;name&quot;: &quot;春风得意马蹄疾&quot;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="8-9-查询全部，设置-source-查询字段，多个逗号隔开"><a href="#8-9-查询全部，设置-source-查询字段，多个逗号隔开" class="headerlink" title="8.9 查询全部，设置 source 查询字段，多个逗号隔开"></a>8.9 查询全部，设置 source 查询字段，多个逗号隔开</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">GET</span> http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span>.x.x:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span>_search?source<span class="hljs-operator">=</span>name<br></code></pre></td></tr></table></figure>

<h3 id="8-10-HEAD-方式查询文档，根据状态码判断数据是否存在（节省传输效率）"><a href="#8-10-HEAD-方式查询文档，根据状态码判断数据是否存在（节省传输效率）" class="headerlink" title="8.10 HEAD 方式查询文档，根据状态码判断数据是否存在（节省传输效率）"></a>8.10 HEAD 方式查询文档，根据状态码判断数据是否存在（节省传输效率）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs sql">HEAD http:<span class="hljs-operator">/</span><span class="hljs-operator">/</span><span class="hljs-number">192.168</span><span class="hljs-number">.147</span><span class="hljs-number">.132</span>:<span class="hljs-number">9200</span><span class="hljs-operator">/</span>my_doc<span class="hljs-operator">/</span>_doc<span class="hljs-operator">/</span><span class="hljs-number">11</span><br><br>存在：<span class="hljs-number">200</span><br>不存在：<span class="hljs-number">404</span><br></code></pre></td></tr></table></figure>



<h3 id="8-11-文档乐观锁控制"><a href="#8-11-文档乐观锁控制" class="headerlink" title="8.11 文档乐观锁控制"></a>8.11 文档乐观锁控制</h3><h2 id="番外：mac-多机器克隆修改项"><a href="#番外：mac-多机器克隆修改项" class="headerlink" title="番外：mac 多机器克隆修改项"></a>番外：mac 多机器克隆修改项</h2><ol>
<li>安装虚机，启动进入</li>
<li>ipaddr 搜索 link/ether 拷贝 Mac 地址备用</li>
<li>修改 /etc/udev/rules.d/70-persistent0ipoib.rules<ul>
<li>修改 ACTION==”add” 这一行 address，粘贴 mac 地址，保存</li>
</ul>
</li>
<li>修改ip地址，打开  /etc/sysconfig/network-scripts/ifcfg-ens33 <ul>
<li>IPADDR 改成网段的任意静态 ip 即可</li>
<li>HWADDR=”” 改成备用的物理地址</li>
</ul>
</li>
<li>重启计算机或者使用 service network restart</li>
<li>验证 ipaddr</li>
<li>修改虚机名和 secureCRT 连接名</li>
</ol>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a>
                    
                      <a class="hover-with-bg" href="/categories/%E5%90%8E%E7%AB%AF/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎</a>
                    
                      <a class="hover-with-bg" href="/tags/ElasticSearch/">ElasticSearch</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/05/08/%E5%90%8E%E7%AB%AF/java/Java%E6%B3%9B%E5%9E%8B/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Java 泛型</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/05/08/%E5%90%8E%E7%AB%AF/java/BigDecimal%E8%88%8D%E5%85%A5%E6%A8%A1%E5%BC%8F/">
                        <span class="hidden-mobile">BigDecimal 舍入模式</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="SOHUCS" sid='http://example.com/2023/05/08/%E5%90%8E%E7%AB%AF/java/ElasticSearch/'></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#SOHUCS', function() {
      Fluid.utils.createScript("https://changyan.sohu.com/upload/changyan.js", function() {
        window.changyan.api.config({"appid":"cywjv2D9l","appkey":"2bf2f1231299e92b26393ba6fb2ad9d8"})
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
    风间小栈出品
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
